import { http } from '@/utils/request'
import type {
  SysListRoleParamsType,
  SysRoleDetailsType,
  SysRoleListType,
  SysRoleWriteParamsType
} from './model'

/**
 * 获取角色列表
 * @returns SysRoleListType[]
 */
export const getRoleListAPI = (params?: SysListRoleParamsType) => {
  return http.request<PageResult<SysRoleListType>>('get', '/sys_role', {
    params
  })
}

/**
 * 获取角色详情
 * @param id
 * @returns SysRoleDetailsType
 */
export const getRoleDetailAPI = (id: number) => {
  return http.request<SysRoleDetailsType>('get', `/sys_role/${id}`)
}

/**
 * 新增角色
 * @param data SysRoleWriteParamsType
 * @returns
 */
export const addRoleAPI = (data: SysRoleWriteParamsType) => {
  return http.request('post', '/sys_role', { data })
}

/**
 * 修改角色
 * @param id 角色Id
 * @param data SysRoleWriteParamsType
 * @returns
 */
export const updateRoleAPI = (id: number, data: SysRoleWriteParamsType) => {
  return http.request('put', `/sys_role/${id}`, { data })
}

/**
 * 删除角色
 * @param id 角色Id
 * @returns
 */
export const deleteRoleAPI = (id: number) => {
  return http.request('delete', `/sys_role/${id}`)
}
